﻿using UnityEngine;

namespace AudioStudio
{
    /// <summary>
    /// 默认的听音者
    /// </summary>
    [AddComponentMenu("AudioStudio/DefaultAudioListener")]
    [DisallowMultipleComponent]
    public class DefaultAudioListener : AudioGameObject
    {
        public static bool FollowCameraForward = false;        

        new void Awake()
        {
            base.Awake();
            ListenerManager.SetListener(Player);
        }

        new void OnDestroy()
        {            
            ListenerManager.RemoveListener(Player);
            base.OnDestroy();
        }

        public override Vector3 GetForward()
        {
            if(FollowCameraForward && Camera.main != null)
            {
                return Camera.main.transform.forward;
            }
            return transform.forward;
        }

        public override Vector3 GetUp()
        {
            if (FollowCameraForward && Camera.main != null)
            {
                return Camera.main.transform.up;
            }
            return transform.up;
        }
    }
}